<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>
    数据一：
    <input type="text" id="num1">
</p>
<p>
    数据二：
    <input type="text" id="num2">
</p>
<p>
    <button onclick="sun(1)">相加</button>
    <button onclick="sun(2)">相减</button>
    <button onclick="sun(3)">相乘</button>
    <button onclick="sun(4)">相除</button>

</p>
<p>
    结果：
    <input type="text" id="num3">
</p>
<script>
    function sun(n) {
        var text = Number(document.querySelector("#num1").value);
        var text1 = Number(document.querySelector("#num2").value);
        var res = 0;
        if(n == 1){
            res = text +text1;
        }
        if(n == 2){
            res = text - text1;
        }
        if(n == 3){
            res = text * text1;
        }
        if(n == 4){
            if(text1 == 0){
                alert('被除数不能是0！')
            }else{
                res = text / text1;
            }
        }
        document.querySelector('#num3').value = res
    }
</script>
</body>
</html>